<template>
  <div class="app-container">
    <el-col :span="18">
      <el-row>
        <el-button @click="drawer = true" type="primary" round>新增按钮</el-button>
        <el-button type="danger" round>批量删除</el-button>
      </el-row>
    </el-col>
    <el-col :span="6">
      <el-input placeholder="请输入内容" v-model="input">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
    </el-col>
    <el-table :data="list" style="width: 100%" max-height="300">
      <el-table-column fixed type="selection" width="70"></el-table-column>
      <el-table-column label="#" type="index" align="center" width="60"></el-table-column>
      <el-table-column prop="date" label="日期" width="150"> </el-table-column>
      <el-table-column prop="title" label="标题" width="120"> </el-table-column>
      <el-table-column prop="author" label="发布者" width="120">
      </el-table-column>
      <el-table-column prop="type" label="类型" width="120"> </el-table-column>
      <el-table-column prop="time" label="时间" sortable></el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button type="text" size="small"> 删除 </el-button>
          <el-button type="text" size="small"> 修改</el-button>
          <el-button type="text" size="small"> 查看 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400">
      </el-pagination>
      <el-drawer size="80%" title="我是外面的 Drawer" :visible.sync="drawer" :with-header="false">
        <span>
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="标题">
              <el-input :disabled="see" v-model="form.title"></el-input>
            </el-form-item>
            <el-form-item label="作者">
              <el-input :disabled="true" v-model="form.author"></el-input>
            </el-form-item>
            <el-form-item label="类别" prop="type">
              <el-select :disabled="see" v-model="form.cid" placeholder="请选择类别">
                <el-option v-for="(item, index) in classify" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="时间">
              <el-select :disabled="see" v-model="form.time" placeholder="请选择用时">
                <el-option label="1分钟" value="1分钟"></el-option>
                <el-option label="2分钟" value="2分钟"></el-option>
                <el-option label="5分钟" value="5分钟"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="内容">
              <mavonEditor v-model="form.content" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="add">确定</el-button>
              <el-button @click="drawer = false">取消</el-button>
            </el-form-item>
          </el-form>
        </span>
      </el-drawer>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'
import { mavonEditor } from "mavon-editor";
import "mavon-editor/dist/css/index.css";
export default {
  data () {
    return {
      drawer: false,
      form: {
        author:'situ'
      },
      see: false,
      currentPage: 5,
      input:''
    }
  },
  methods: {
    add(){
      this.postMsbd(this.form)
      // console.log(this.form)
    },
    ...mapActions('msbd', ['getList','getClassify','postMsbd']),
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
    },
  },
  mounted () {
    this.getList()
    this.getClassify()
  },
  computed: {
    ...mapState('msbd', ['list','classify'])
  },
  components: {
    mavonEditor,
  },
}
</script>

<style scoped>
</style>